<?php
/**
 * Created by DocModel.class.php.
 * User: tqj
 * Date: 2017-05-27
 * Time: 22:06
 */

namespace Admin\Model;
use  Think\Model;

class DocModel extends  Model
{
    public function  saveData( $post,$file){
        //判断是否有文件需要处理
        if(!$file['error']){
            //处理上传
            $cfg=array(
                //配置上传路径
                'rootPath'=>WORKING_PATH.UPLOAD_ROOT_PATH,
            );
            $upload= new \Think\Upload($cfg);
            $info=$upload->uploadOne($file);
            if($info){
                $post['file_path']=UPLOAD_ROOT_PATH.$info['savepath'].$info['savename'];
                $post['file_name']=$info['name'];
                $post['hasfile']=1;
            }
        }
        $post['addtime']=time();
         return  $this->add($post);
    }
    public  function  updateDoc($post,$file){
        if($file[error]==0){
            $cfg=array(
                "rootPath"=>WORKING_PATH.UPLOAD_ROOT_PATH,
            );
            $upload= new \Think\Upload($cfg);
            $info=$upload->uploadOne($file);
            if($info){
                $post['file_path']=UPLOAD_ROOT_PATH.$info['savepath'].$info['savename'];
                $post['file_name']=$info['name'];
                $post['hasfile']=1;
            }
        }
        return  $this->save($post);
    }
}